package com.mairuide.casemanage.controller;

import com.mairuide._frame.base.BaseController;
import com.mairuide.casemanage.pojo.CaseType;
import com.mairuide.casemanage.service.CaseTypeService;
import freemarker.ext.beans.HashAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: zyj
 * @Date: 2018/12/28 16:22
 * @Description:
 */
@Controller
@RequestMapping("/casetype")
public class CaseTypeComtroller extends BaseController {
    @Autowired
    private CaseTypeService caseTypeService;

    @RequestMapping("/allcasetype")
    @ResponseBody
    public List<CaseType> getAllCaseType(){
        List<CaseType> allCaseType = caseTypeService.getAllCaseType();
        return allCaseType;
    }

    @RequestMapping("/updatecasetype")
    @ResponseBody
    public Object updateCaseType(CaseType caseTypet){
        Map<String,String> map = new HashMap<>();
        if (caseTypet.getId()!=null){
            caseTypet.setIsDelect(0);
            caseTypeService.save(caseTypet);
            map.put("msg","修改成功");
        }else {
            map.put("msg","修改失败");
        }
        return map;
    }

    @RequestMapping("/savecasetype")
    @ResponseBody
    public Object saveCaseType(CaseType caseType){
        CaseType type = caseTypeService.getisExist(caseType.getTypeName());
        Map<String,String> map = new HashMap<>();
        if (type!=null){//存在就修改删除状态
            type.setIsDelect(0);
            caseTypeService.save(caseType);
        }else {
            caseTypeService.save(caseType);
        }
        return map.put("msg","添加成功");
    }

    @RequestMapping("/delectcasetype")
    @ResponseBody
    public Object delect(Integer id){
        Map<String,String>map = new HashMap<>();
        if (id!=null){//存在就修改删除状态
            CaseType one = caseTypeService.findOne(id);
            one.setIsDelect(1);
            caseTypeService.save(one);
            return map.put("msg","删除成功");
        }else {
            return map.put("msg","删除失败");
        }

    }

}
